package com.spacex.danhuang.polive.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.spacex.danhuang.polive.AppDataClass.AllShowUserData;
import com.spacex.danhuang.polive.R;

import java.util.List;

/**
 * Created by Administrator on 2016/6/7 0007.
 */
public class AllShowAdapter extends RecyclerView.Adapter<AllShowAdapter.AllShowViewHolder> {

    private List<AllShowUserData> mAllShowUserDataList;

    public AllShowAdapter(List<AllShowUserData> list) {
        mAllShowUserDataList = list;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    public AllShowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.all_show_recycler_item, parent, false);
        return new AllShowViewHolder(v);
    }

    @Override
    public void onBindViewHolder(AllShowViewHolder holder, final int position) {
        AllShowUserData allShowUserData = mAllShowUserDataList.get(position);
        holder.tv_all_show_nickname.setText(allShowUserData.getNickname());

        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onItemClick(position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mAllShowUserDataList.size();
    }

    public class AllShowViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_all_show_nickname;

        public AllShowViewHolder(View itemView) {
            super(itemView);

            tv_all_show_nickname = (TextView)itemView.findViewById(R.id.tv_all_show_nickname);
        }
    }
}
